package com.itheima.hashtable;

import java.util.HashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Demo01 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        HashMap<String, String> map = new HashMap<>();

        long start = System.currentTimeMillis();
        FutureTask<String> task = new FutureTask<>(() -> {
            for (int i = 0; i < 10000000; i++) {
                map.put(i + "", i + "");
            }
            return "存完了";

        });
        Thread t1 = new Thread(task);
        FutureTask<String> task2 = new FutureTask<>(() -> {
            for (int i = 10000000; i < 20000000; i++) {
                map.put(i + "", i + "");
            }
            return "存完了";

        });
        Thread t2 = new Thread(task2);
        t1.start();
        t2.start();
        task.get();
       task2.get();
        long end = System.currentTimeMillis();


        //Thread.sleep(2000);
       // map.forEach((k,v)-> System.out.println(k+"###"+v));
       /* for (int i = 0; i < 200000; i++) {
            System.out.println(map.get(i+""));
        }
*/
        System.out.println("使用了"+(end-start));//使用了130  117
    }
}
